package cn.ren.hai.core.entity;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 自动补充插入或更新时的值
 * @author lr
 * @date 2019-06-03 18:26
 */
@Component
public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("del","0");
        metaObject.setValue("status",0);
        metaObject.setValue("createdId",1L);
        metaObject.setValue("createdName","admin");
        metaObject.setValue("createdTime", LocalDateTime.now());
        metaObject.setValue("sort",0);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updatedId",1L);
        metaObject.setValue("updatedName","admin");
        metaObject.setValue("updatedTime", LocalDateTime.now());
    }
}